package game.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import common.controller.base.BaseController;
import common.model.po.GItem;
import common.model.po.GUserProduction;
import common.model.request.base.PaginationRequest;
import common.model.response.base.Result;
import common.service.CommonSysUserService;
import game.model.request.GenerateProductionNameRequest;
import game.model.request.ModifyProductionNameRequest;
import game.model.request.SaveUserProductionRequest;
import game.model.request.SearchUserProductionRequest;
import game.model.vo.ProductionCollectionVo;
import game.service.GItemService;
import game.service.GUserProductionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 产线收藏
 *
 * @author 米泽鹏
 * @since 2023-09-26 下午 10:15
 */
@Api(tags = "产线收藏管理")
@RestController
@RequestMapping("/game/g-user-production")
public class GUserProductionController extends BaseController {

	@Resource
	private GUserProductionService service;
	@Resource
	private CommonSysUserService userService;
	@Resource
	private GItemService itemService;

	@ApiOperation(value = "产线收藏分页查询", notes = "产线收藏分页查询")
	@PostMapping("/readOnly/pageUserProduction")
	public Result<Page<ProductionCollectionVo>> pageUserProduction(@ApiParam(value = "产线收藏分页查询请求", required = true) @RequestBody @Validated PaginationRequest<SearchUserProductionRequest, GUserProduction> paginationRequest) {
		return successWithData(service.pageUserProduction(paginationRequest));
	}

	@ApiOperation(value = "产线收藏新增或更新", notes = "产线收藏新增或更新")
	@PostMapping("/saveUserProduction")
	public Result<?> saveUserProduction(@ApiParam(value = "产线收藏新增或更新请求", required = true) @RequestBody @Validated SaveUserProductionRequest request) {
		return service.saveUserProduction(request);
	}

	@ApiOperation(value = "产线收藏删除", notes = "产线收藏删除")
	@DeleteMapping("/deleteUserProduction/{id}")
	public Result<?> deleteUserProduction(@ApiParam(value = "产线收藏id", required = true) @PathVariable Long id) {
		return service.deleteUserProduction(id);
	}

	@ApiOperation(value = "获取所有物品", notes = "获取所有物品")
	@GetMapping("/readOnly/getAllItem")
	public Result<?> getAllItem() {
		return successWithData(itemService.lambdaQuery().select(GItem::getId, GItem::getItemName, GItem::getImage).list());
	}

	@ApiOperation(value = "获取所有用户", notes = "获取所有用户")
	@GetMapping("/readOnly/getAllUser")
	public Result<?> getAllUser() {
		return Result.successWithData(userService.list());
	}

	@ApiOperation(value = "修改产线名称", notes = "修改产线名称")
	@PostMapping("/modifyProductionName")
	public Result<?> modifyProductionName(@ApiParam(value = "修改产线名称请求", required = true) @RequestBody @Validated ModifyProductionNameRequest request) {
		return service.modifyProductionName(request);
	}

	@ApiOperation(value = "根据id查询产线收藏", notes = "根据id查询产线收藏")
	@PostMapping("/readOnly/getUserProductionById/{id}")
	public Result<GUserProduction> getUserProductionById(@ApiParam(value = "产线收藏id", required = true) @PathVariable Long id) {
		return successWithData(service.getById(id));
	}

	@ApiOperation(value = "生成不重复的产线名称", notes = "生成不重复的产线名称")
	@PostMapping("/readOnly/generateProductionName")
	public Result<String> generateProductionName(@ApiParam(value = "生成不重复的产线名称请求", required = true) @RequestBody @Validated GenerateProductionNameRequest request) {
		return service.generateProductionName(request);
	}

}
